package com.glp.common.config;

import com.glp.common.constants.FileConstants;
import org.springframework.boot.web.servlet.ServletContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.SessionTrackingMode;
import java.util.Collections;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    /**
     * 解决 有时候重定向后的url 上携带 jsessionid 的问题
     * @return
     */
    @Bean
    public ServletContextInitializer servletContextInitializer1() {
        return servletContext -> servletContext.setSessionTrackingModes(Collections.singleton(SessionTrackingMode.COOKIE) );
    }

    /**
     * 配置文件虚拟路径
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer(){
        return new WebMvcConfigurer() {
            //前端获取到本地资源映射
            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                registry.addResourceHandler(FileConstants.REPORT_IMG_VIRTUAL_UTL + "**").addResourceLocations("file:/" + FileConstants.REPORT_IMG_LOCAL_URL);
            }
        };
    }
}
